$(function() {
    category.init();
    category.Search();
    $(window).hashchange(category._Search);
});

var category =
{
    init: function() {
        //binding events.
        $('#content a[delsn]').live("click", function() {
            category.delConfirm($(this).attr("delsn"));
        });
    }
    , delConfirm: function(sn) {
        category.currentSN = parseInt(sn, 10);
        var objfun = function() {
            category.doDel(sn);
        }
        utility.showPopUp(m.Msg0003, 3, objfun);
    }
    , doDel: function(x) {
        var param = { sn: x };
        var cb = function() { window.parent.location.reload(); }
        utility.ajaxext("VoiceService/DeleteCategory", param, "POST", cb);
    }
    , Search: function() {
        var param = { page: 1, searchkey: $('#searchkey').val() };
        utility.setObjToHash(param);
    }
    , _Search: function() {
        var param = utility.addPageToPara(utility.getObjFromHash());
        utility.service('VoiceService/SearchCategory', param, 'POST', function(data) {
            if (data.code > 0) {
                if (data.code > 1) {
                    $('#bolisting').html('<tr><td colspan="2" class="align-center">' + data.msg + '</td></tr>');
                    utility.formatPaging($('#pageing'), 1, 1);
                } else {
                    var templatepara = { 'pList': data.d, 'g': g };
                    utility.template("Voice/Categorylisting.html", function(template) {
                        $('#bolisting').html(template.process(templatepara));
                        PageInitial.InitialPopupDiv();
                    }, "categorylisting");
                }
            } else {
                utility.showPopUp(data.msg, 1);
            }
        });
    }
};
